package com.atwisdom.star.common.vo;

/**
 * 反返结果数据处理
 */
public class JsonResult {
    public static <T> ResultInfo<T> success() {
        return success(null);
    }

    public static <T> ResultInfo<T> success(T t) {
        ResultInfo<T> res = new ResultInfo<T>();
        res.setSuccess(true);
        res.setCode(StatusCode.SUCCESS.getCode());
        res.setMessage(StatusCode.SUCCESS.getMessage());
        res.setData(t);
        return res;
    }

    public static <T> ResultInfo<T> success(int code, String message) {
        ResultInfo<T> res = new ResultInfo<T>();
        res.setSuccess(true);
        res.setCode(code);
        res.setMessage(message);
        return res;
    }

    public static <T> ResultInfo<T> error(StatusCode code) {
        ResultInfo<T> res = new ResultInfo<T>();
        res.setSuccess(false);
        res.setCode(code.getCode());
        res.setMessage(code.getMessage());
        return res;
    }

    public static <T> ResultInfo<T> error(Integer code, String message) {
        ResultInfo<T> res = new ResultInfo<T>();
        res.setSuccess(false);
        res.setCode(code);
        res.setMessage(message);
        return res;
    }

    public static <T> ResultInfo<T> error(Exception e, StatusCode code) {
        ResultInfo<T> res = new ResultInfo<T>();
        res.setSuccess(false);
        res.setCode(code.getCode());
        res.setMessage(e.getMessage());
        return res;
    }
}
